#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Import system-package
import sys

# Import own WhateverFuse package for main functionality
import WhateverFuse

# Set global prog name variable
PROG_NAME="MyWhateverInADir"

# Import type-packages for fuse-functionality
FUSE_TYPES=[]

# Import temporary/memory-filesystem
try:
	from MyTypeTemp import MyTypeTemp
	FUSE_TYPE_TEMP="temp"
	FUSE_TYPES.append(FUSE_TYPE_TEMP)
except:
	#print "Package 'MyTypeTemp' could not be imported."
	pass
# End 

# Import JSON-filesystem
try:
	from MyTypeJSON import MyTypeJSON
	FUSE_TYPE_JSON="json"
	FUSE_TYPES.append(FUSE_TYPE_JSON)
except:
	#print "Package 'MyTypeJSON' could not be imported."
	pass
# End try/except

# ----------

if __name__ == '__main__':
	# Set FUSE-version
	WhateverFuse.fuse.fuse_python_api=WhateverFuse.fuse.FUSE_PYTHON_API_VERSION

	# Initializing FUSE-Object
	WhateverFuse=WhateverFuse.WhateverFuse(version="%prog, FUSE: "+WhateverFuse.fuse.__version__, usage=PROG_NAME+", "+WhateverFuse.fuse.Fuse.fusage, dash_s_do='setsingle')

	# Adding MyWhateverInADir-specific parameters
	optGroup=WhateverFuse.parser.add_option_group(PROG_NAME+" specific options")
	# Common
	optGroup.add_option("--my-type", help="Sets type of fuse-filesystem: %s" % str(FUSE_TYPES), action="store", type="string", metavar="fuseType", dest="fuseType", default="temp")
	optGroup.add_option("--my-verbose", help="Set verbosity, used with fuse-mount-options -d or -f.", action="store_true", dest="verbose", default=False)
	optGroup.add_option("--my-encoding", help="Defines which encoding has to be used, default latin1.", action="store", type="string", metavar="encoding", dest="encoding", default="latin1")

	# JSON
	optGroupJSON=WhateverFuse.parser.add_option_group("JSON options")
	optGroupJSON.add_option("--json-filename", help="Defines the JSON-File, if no file is given a temporary name will be assigned.", action="store", type="string", metavar="filename", dest="jsonFilename", default=None)
	optGroupJSON.add_option("--json-indentation", help="Defines with how many spaces the json-file will be indented with.", action="store", type="int", metavar="indentation", dest="jsonIndentation", default=None)
	optGroupJSON.add_option("--json-no-translate-boolean", help="Defines that strings will NOT be checked if they are boolean-valued, like \"True\" -> True.", action="store_true", dest="jsonTranslateBoolean", default=False)
	optGroupJSON.add_option("--json-no-translate-numbers", help="Defines that strings will NOT be checked if they are number-valued, like \"123\" -> 123 or \"123.45\" -> 123.45", action="store_true", dest="jsonTranslateNumbers", default=False)
	optGroupJSON.add_option("--json-no-translate-none", help="Defines that strings will NOT be checked if they are None-valued, like \"None\" -> None", action="store_true", dest="jsonTranslateNone", default=False)

	# Parse parameters
	options, args=WhateverFuse.parser.parse_args()

	# Fuse-Type not in types
	if options.fuseType not in FUSE_TYPES:
		print "Fuse type '%s' must be of type %s" % (options.fuseType, str(FUSE_TYPES))
		sys.exit(0)
	# End if

	# Transfer Parameters

	# Common - Part 1
	WhateverFuse.verbosity.setVerbosity(options.verbose)

	# Temp
	if options.fuseType==FUSE_TYPE_TEMP:
		WhateverFuse.dataStorage=MyTypeTemp({})
	# End if

	# JSON
	if options.fuseType==FUSE_TYPE_JSON:
		if options.jsonFilename==None:
			print "Fuse type %s requires a filename (--json-filename)." % FUSE_TYPE_JSON
			sys.exit(0)
		# End if
		
		# Set JSON-specific parameters
		WhateverFuse.dataStorage=MyTypeJSON(options.jsonFilename, options.encoding)
		WhateverFuse.dataStorage.setIndentation(options.jsonIndentation)
		WhateverFuse.dataStorage.setTranslateBoolean(not options.jsonTranslateBoolean)
		WhateverFuse.dataStorage.setTranslateNumbers(not options.jsonTranslateNumbers)
		WhateverFuse.dataStorage.setTranslateNone(not options.jsonTranslateNone)
	# End if

	# Common - Part 2
	WhateverFuse.dataStorage.verbosity.setVerbosity(options.verbose)

	# Start FUSE
	WhateverFuse.main()
# End if		
